package com.fengyun;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 自定义ApplicationContext
 */
public class MyClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {

	/**
	 * 调用父类构造，读取本地的configLocations
	 *
	 * @param configLocations
	 */
	public MyClassPathXmlApplicationContext(String... configLocations) {
		super(configLocations);
	}

	/**
	 * 重写初始化属性资源的方法
	 */
	@Override
	protected void initPropertySources() {
		// 设置系统中的属性值
		getEnvironment().setRequiredProperties("username");
	}

	/**
	 * 重写定制话bean工厂的方法
	 * 修改是否允许bean定义和是否允许循 环依赖的属性
	 *
	 * @param beanFactory the newly created bean factory for this context
	 */
	@Override
	protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
		super.setAllowBeanDefinitionOverriding(false);
		super.setAllowCircularReferences(false);
		// 修改父类中AllowBeanDefinitionOverriding和AllowCircularReferences的属性值，
		// 去覆盖beanFactory中AllowBeanDefinitionOverriding和AllowCircularReferences的属性值
		super.resetCommonCaches();
	}
}
